{% extends "base.html" %}

{% block title %}搜索动画{% endblock %}

{% block content %}

    <form method="get" action="{% url 'search_anime' %}">  
        <input type="text" name="theme" placeholder="请输入系列名称" value="{{ request.GET.theme }}">  
        <button type="submit">查询</button>  
    </form>  
    {% if results %}  
    <table>
        <tr class="detail_head">
            <th>系列</th>
            <th>季数</th>
            <th>副标题</th>
            <th>集数</th>
            <th>开播日期</th>
            <th>制作公司</th>
        </tr>
        {% for result in results %}
        <tr class="detail_text">
            <td class="num">{{ result.theme }}</td>
            <td class="num">{{ result.season }}</td>
            <td class="num">{{ result.subtitle }}</td>
            <td class="num">{{ result.episodes }}</td>
            <td class="date">{{ result.date_start }}</td>
            <td class="num"><input type="text" name="producer" placeholder="{{ result.producer }}"></td>
        </tr>
        {% endfor %}
    </table>
    {% else %}  
    <p>未找到相关结果！</p>  
    {% endif %}  

    <script>
        var num_elements = document.getElementsByClassName("num");
        for(var n = 0; n<num_elements.length; n++){
            if(num_elements[n].innerHTML == 'None'){
                num_elements[n].innerHTML = '';
            }
        }

        var date_elements = document.getElementsByClassName("date");
        for(var i = 0; i<date_elements.length; i++){
            var d = new Date(date_elements[i].innerHTML);
            var y = d.getFullYear();
            var m = d.getMonth() + 1;
            if(m < 10){
                m = '0' + m;
            }
            var day = d.getDate();
            if(day < 10){
                day = '0' + day;
            }
            if(y){
                date_elements[i].innerHTML = y + '-' + m + '-' + day;
            }else{
                date_elements[i].innerHTML = '';
            }  
        }

    </script>

{% endblock %}